Hệ thống quản lý ISP trong PHP

1 <?php
2
3     
// Start from getting the hader which contains some settings we need
4     require_once
'includes/headx.php';
5
6     
// require the admins class which containes most functions applied to admins
7     require_once
"includes/classes/admin-class.php";
8
9     $admins =
new Admins($dbh);
10
11     
// check if the form is submitted
12     $page = isset($_GET[
'p' ])?$_GET[ 'p' ]:'';
13
14     
if($page == 'add'){
15             $username = $_POST[
'username'];
16             $email = $_POST[
'email'];
17             $password = $_POST[
'password'];
18             $repassword = $_POST[
'repassword'];
19             $fullname = $_POST[
'fullname'];
20             $address = $_POST[
'address'];
21             $contact = $_POST[
'contact'];
22
23             
if (isset($_POST))
24             {
25
26                 $errors = array();
27
28                 
// Check if password are the same
29                 
if (!$admins->ArePasswordSame($_POST['password'], $_POST['repassword']))
30                 {
31                     session::
set('errors', ['The two passwords do not match.']);
32                 }elseif ($admins->adminExists($_POST[
'username'])) {
33                     session::
set('errors', ['This username is already in use by another admin.']);
34                 }elseif (!$admins->addNewAdmin($username, $password, $email, $fullname, $address, $contact)) {
35                     session::
set('errors', ['An error occured while saving the new admin.']);
36                 }
else{
37                     session::
set('confirm', 'New admin added successfully!');
38                     unset($_POST[
'repassword']);
39                 }
40             }
41     }
else if($page == 'del'){
42         $id = $_POST[
'id'];
43         
if (!$admins->deleteUser($id))
44         {
45             echo
"Sorry Data could not be deleted !";
46         }
else {
47             echo
"Well! You've successfully deleted a product!";
48         }
49
50     }
else if($page == 'edit'){
51         $username = $_POST[
'username'];
52         $email = $_POST[
'email'];
53         $full_name = $_POST[
'full_name'];
54         $address = $_POST[
'address'];
55         $contact = $_POST[
'contact'];
56         $user_id = $_POST[
'user_id'];
57         
if (!$admins->updateAdmin($user_id, $username, $email, $full_name, $address, $contact))
58         {
59             
//echo "$user_id $username $email $full_name $address $contact";
60             echo
"Sorry Data could not be Updated !";
61         }
else {
62             $commons->redirectTo(SITE_PATH.
'user.php');
63         }
64
65     }
else{
66         $users = $admins->fetchAdmin();
67         
if (isset($users) && sizeof($users) > 0) {
68             
foreach ($users as $user){ ?>
69                 <tr>
70                     <td scope=
"row"><?=$user->user_id ?></td>
71                     <td>
72                         <button type=
"button" id="edit" class="btn btn-success btn-sm" data-toggle="modal" data-target="#edit-<?=$user->user_id?>">EDIT</button>
73                         <div
class="fade modal" id="edit-<?=$user->user_id?>">
74                             <div
class="modal-dialog" role="document">
75                                 <div
class="modal-content">
76                                     <div
class="modal-header">
77                                         <button type=
"button" class="close" data-dismiss="modal">×</button>
78                                         <h4>Edit Details</h4>
79                                     </div>
80                                     <form method=
"POST">
81                                         <div
class="modal-body">
82                                             <!-- The
async form to send and replace the modals content with its response -->
83                                             <!-- form content -->
84                                             <input type=
"hidden" id="<?=$user->user_id ?>" value="<?=$user->user_id?>">
85
86                                             <div
class="form-group has-success">
87                                                 <label
for="name">Full Name</label>
88                                                 <input type=
"text" class="form-control" id="fnm-<?=$user->user_id?>" value="<?=$user->full_name?>" required>
89                                             </div>
90                                             <div
class="form-group">
91                                                 <label
for="Username">Username</label>
92                                                 <input type=
"text" class="form-control" id="usr-<?=$user->user_id?>" value="<?=$user->user_name?>" required>
93                                             </div>
94                                             <div
class="form-group">
95                                                 <label
for="email">Email</label>
96                                                 <input type=
"text" class="form-control" id="em-<?=$user->user_id?>" value="<?=$user->email?>" required>
97                                             </div>
98                                             <div
class="form-group">
99                                                 <label
for="details">Address</label>
100                                                 <input type=
"text" class="form-control" id="ad-<?=$user->user_id?>" value="<?=$user->address?>" required>
101                                             </div>
102                                             <div
class="form-group">
103                                                 <label
for="contact">Contact</label>
104                                                 <input type=
"text" class="form-control" id="con-<?=$user->user_id?>" value="<?=$user->contact?>" required>
105                                             </div>
106                                         </div>
107                                         <div
class="modal-footer">
108                                             <button type=
"submit" onclick="updateData(<?=$user->user_id?>)" class="btn btn-primary">Update</button>
109                                             <a href=
"#" class="btn btn-warning" data-dismiss="modal">Cancel</a>
110                                         </div>
111                                     </form>
112                                 </div>
113                             </div>
114                         </div>
115                         <button type=
"submit" id="delete" onclick="delData(<?=$user->user_id ?>)" class="btn btn-warning btn-sm disabled">DELETE</button>
116                     </td>
117                     <td
class="search"><?=$user->user_name?></td>
118                     <td
class="search"><?=$user->full_name?></td>
119                     <td
class="search"><?=$user->email?></td>
120                     <td
class="search"><?=$user->contact?></td>
121                     <td
class="search"><?=$user->address?></td>
122                 </tr>
123             <?php
124             }
125         }
126     }
127 ?>


Gõ tìm kiếm nhanh...